package com.wbr.file.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.wbr.file.mapper.CustomerMapper;
import com.wbr.file.pojo.Customer;
import com.wbr.file.service.ImportExcelService;
import com.wbr.file.utils.ReadExcel;

@Service
public class ImportExcelServiceImpl implements ImportExcelService {

	@Autowired
	private CustomerMapper mapper;

	public boolean batchImport(String name, MultipartFile file) {

		boolean b = false;

		// 创建处理EXCEL
		ReadExcel readExcel = new ReadExcel();
		// 解析excel，获取客户信息集合。
		List<Customer> customerList = readExcel.getExcelInfo(name, file);

		if (customerList != null) {
			b = true;
		}

		// 迭代添加客户信息（注：实际上这里也可以直接将customerList集合作为参数，在Mybatis的相应映射文件中使用foreach标签进行批量添加。）
		for (Customer customer : customerList) {
			// customerDoImpl.addCustomers(customer);
			mapper.insert(customer);
		}
		return b;
	}

}
